/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Business;

import Objects.Timework;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Nguyen Kim Manh
 */
public class TimeworkBusiness {
    
     /**
     * Method getTimeworkById() used to get Timework info by TimeworkID
     * @param variable has string type
     * @return objEmployee
     */
    public static Timework getTimeworkById(String TimeworkID){
        Timework tw=new Timework();
        
        String sql="{call sp_getTimeworkByID(?)}";
        ArrayList list=new ArrayList();
        list.add(TimeworkID);
        try {
            ResultSet rs=DBAccess.DB_Connect.executeQuery(sql, list);
            if(rs.next()){
                 tw.setTimeworkID(rs.getString("TimeworkID"));
                tw.setTimeworkDes(rs.getString("Description"));
            }
               
            
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(TimeworkBusiness.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(TimeworkBusiness.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return tw;
    }
    
    /**
     * Method getTimeworkById() used to get Timework info by Description Field
     * @param variable has string type
     * @return objEmployee
     */
    public static Timework getTimeworkByDescription(String Des){
             
        String sql="{call sp_getTimeworkByDescription(?)}";
        ArrayList list=new ArrayList();
        list.add(Des);
         Timework tw=null;
        try {
            ResultSet rs=DBAccess.DB_Connect.executeQuery(sql, list);
            if(rs.next()){
               tw=new Timework();
                 tw.setTimeworkID(rs.getString("TimeworkID"));
                tw.setTimeworkDes(rs.getString("Description"));
            }        
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(TimeworkBusiness.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(TimeworkBusiness.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return tw;
    }
    
    /**
     * Method getAllTimework() used to get all timework information from database
     * @return ArrayList<Timework>
     */
    public static ArrayList<Timework> getAllTimework(){
        ArrayList<Timework> list=new ArrayList<>();
        
        String sql="{call sp_getAllTimework}";
        try {
            ResultSet rs=DBAccess.DB_Connect.executeQuery(sql, null);
            while(rs.next()){
                Timework tw=new Timework();
                tw.setTimeworkID(rs.getString("TimeworkID"));
                tw.setTimeworkDes(rs.getString("Description"));
                
                list.add(tw);
                
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(TimeworkBusiness.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(TimeworkBusiness.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return list;
    }
}
